﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using ClassLibrary.Entity;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblImageMenuDAO
    {
        private DBService _db = null;

        public TblImageMenuDAO(String connectionString)
        {
            _db = new DBService(connectionString);
        }

        // lay hinh anh tuong ung trong MEnu
        public TblImageMenu GetImageMenuByID(int IDMenu, int ID)
        {

            TblImageMenu imageMenu = new TblImageMenu();
            try
            {
                DataTable dt = _db.ExeSP_DataTable("sp_TblMenuImage_Lst",
                   new string[] { "@p_IDMenu", "@Id" },
                   new object[] { IDMenu, ID },
                  CommandType.StoredProcedure);

                foreach (DataRow dr in dt.Rows)
                {
                    imageMenu.ID = Convert.ToInt32(dr["ID"].ToString());
                    imageMenu.ImageURL = dr["ImageURL"].ToString();
                    imageMenu.IsDefault = Convert.ToBoolean(dr["IsDefault"].ToString());
                    imageMenu.IDMenu = Convert.ToInt32(dr["IDMenu"].ToString());

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return imageMenu;
        }
    }
}
